package com.tjl.synchronized_practice;
/*请编写程序，不使用任何同步技术，模拟三个窗口同时卖100张票的情况，运行并打印结果，观察到错误的数据，并解释出现错误的原因。*/
public class Test {
    public static void main(String[] args) {
        Ticket ticket = new Ticket(1000, 100);

        //任务对象
        DrawThread drawThread = new DrawThread(ticket);
        //启动三个线程
        new Thread(drawThread,"窗口1").start();
        new Thread(drawThread,"窗口2").start();
        new Thread(drawThread,"窗口3").start();




    }
}


//实现Runnable接口，重写run方法，对tick对象进行多线程处理
class DrawThread implements Runnable{
    private  Ticket ticket; //公共资源

    public DrawThread() {
    }

    public DrawThread(Ticket ticket) {
        this.ticket = ticket;
    }

    @Override
    public void run() {

        while (ticket.getNumber()>0){
            ticket.saleTicket();

        }

    }
}